home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 4
/
QRZ Ham Radio Callsign Database - Volume 4.iso
/
files
/
loggers
/
qrate.exe
/
RATE.C
< prev
next >
Wrap
Text File
|
1993-08-28
|
4KB
|
155 lines
/*
RATE calculator for CT and other similar log files
by Peter Jennings VE3SUN 72470.3171@compuserve.com
Released to the Public Domain 1993.
Compiled with Turbo C 2.0 - any model.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
main (int argc,char *argv[])
{
FILE *ptr1;
FILE *ptr2;
char record[256];
long incnt = 0;
long qcnt=0;
int offset = 0;
int time,ltime=-1,minute,i,rate1,rate10,rate60,wminute,mtime;
int max1=0, max10=0, max60=0;
int tmax1=0,tmax10=0,tmax60=0;
long minutes[60],hrago=0;
char *p;
if ( argc < 3 )
{
printf( "\nRATE infile reportfile [offset]\n\n"
"Calculates QSO rates for 1 minute, 10 minutes, and 1 hour.\n\n"
"infile is any file with 4 digit times beginning at column [offset]\n\n"
"reportfile will be created or appended to.\n\n"
"offset is an optional column offset to the time column (0 origin).\n"
" not needed for CT *.ASC *.RES *.ALL files.\n");
exit(1);
}
if ((ptr1 = fopen(argv[1],"r"))==NULL)
{
printf("\nUnable to open %s\n",argv[1]);
exit(1);
}
if ((ptr2 = fopen(argv[2],"a"))==NULL)
{
printf("\nUnable to create %s\n",argv[2]);
exit(1);
}
offset = 0;
if ( strstr(strupr(argv[1]),".RES") ) offset = 9;
if ( strstr(argv[1],".ALL") ) offset = 15;
if ( strstr(argv[1],".ASC") ) offset = 25;
if ( argc > 3 ) offset = atoi(argv[3]);
printf("\n\nTime field offset for %s is %d\n\n",argv[1],offset);
for(i=0; i<60; i++)
minutes[i] = 0;
while(1)
{
memset(record,0,256);
if ( fgets(record,256,ptr1) == NULL ) break;
incnt++;
if ( qcnt < 5 )
{
printf("%s",record);
fprintf(ptr2,"%s",record);
}
if ( qcnt ==5 )
{
for( i=0; i<offset; i++) printf(" ");
printf("^^^^");
printf("\n\nPress any key to continue.... Esc to quit.\n\n");
if ( 0x1b == getch()) exit(1);
}
p = strtok(record+offset," \t\n\r");
/**********/
if ( strlen(p) < 3 || strlen(p) >4 ) continue;
if ( !isdigit(p[0]) || !isdigit(p[1]) || !isdigit(p[2]) || !isdigit(p[3]) ) continue;
qcnt++;
time = atoi(p);
mtime = 60*(time/100)+time%100;
if ( ltime > mtime ) /* the next day begins */
mtime = mtime + 1440;
if ( (mtime - ltime) > 1 )
{
for( i=ltime+1; i < mtime; i++)
minutes[i%60] = minutes[ltime%60];
}
minute = atoi(p+2);
if ( mtime%1440 != ltime )
hrago = minutes[ minute ];
ltime = mtime%1440;
minutes[ minute ] = qcnt;
wminute = minute-1;
if ( wminute < 0 ) wminute += 60;
rate1 = qcnt-minutes[wminute];
if ( rate1 > max1 )
{
max1 = rate1;
tmax1 = time;
if ( qcnt > 10 )
printf("%10.04d %10d* %10d %10d \n",time,max1,max10,max60);
}
wminute = minute-10;
if ( wminute < 0 ) wminute += 60;
rate10 = qcnt-minutes[wminute];
if ( rate10 > max10 )
{
max10 = rate10;
tmax10 = time;
if ( qcnt > 20 )
printf("%10.04d %10d %10d* %10d \n",time,max1,max10,max60);
}
rate60 = qcnt - hrago;
if ( rate60 > max60 )
{
max60 = rate60;
tmax60 = time;
if ( mtime > 60 && qcnt > 20 )
printf("%10.04d %10d %10d %10d*\n",time,max1,max10,max60);
}
}
fclose(ptr1);
printf( "\n%12ld records read from %s\n" ,
incnt, argv[1] );
printf("\n%10.04d: %10d per minute (%d/hr)\n",tmax1,max1,max1*60);
printf("%10.04d: %10d per 10 minutes (%d/hr)\n",tmax10,max10,max10*6);
printf("%10.04d: %10d per hour\n",tmax60,max60);
printf("\nTotal Qs: %10ld Average %10ld per hour\n\n",qcnt,qcnt/48);
fprintf(ptr2, "\n%12ld records read from %s\n" ,
incnt, argv[1] );
fprintf(ptr2,"\n%10.04d: %10d per minute (%d/hr)\n",tmax1,max1,max1*60);
fprintf(ptr2,"%10.04d: %10d per 10 minutes (%d/hr)\n",tmax10,max10,max10*6);
fprintf(ptr2,"%10.04d: %10d per hour\n",tmax60,max60);
fprintf(ptr2,"\nTotal Qs: %ld Average rate: %ld per hour\n\n",qcnt,qcnt/48);
fprintf(ptr2,"--------------------------------------------------\n");
fclose(ptr2);
}